/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-06-21
 * Time: 11:35
 * To BE A Better Person-2020-3-2
 */
import java.util.*;
public class TestDemo {
    public static boolean isNumber(String token) {
        return !("+".equals(token) || "-".equals(token) || "*".equals(token) || "/".equals(token));
    }
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack=new Stack<>();
        for(int i=0;i<tokens.length;i++){
            if(isNumber(tokens[i])){
                int temp=Integer.parseInt(tokens[i]);
                stack.push(temp);
            }
            if(tokens[i].equals("+")||tokens[i].equals("-")||tokens[i].equals("*")||tokens[i].equals("/")){
                int num1=stack.pop();
                int num2=stack.pop();
                switch (tokens[i]){
                    case "+":
                        stack.push(num2+num1);
                        break;
                    case "-":
                        stack.push(num2-num1);
                        break;
                    case "*":
                        stack.push(num2*num1);
                        break;
                    case "/":
                        stack.push(num2/num1);
                        break;
                }
            }
        }
        int ret= stack.pop();
        return ret;
    }
    public static boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack=new Stack<>();

        int j=1;//指向pushA的值
        stack.push(pushA[0]);
        for(int i=0;i<popA.length;i++){
            while(stack.peek()!=popA[i] && j<pushA.length && !stack.empty()){
                stack.push(pushA[j]);
                j++;
            }
            //相等的情况
            if(stack.peek()==popA[i]){
                stack.pop();
            }else{
                return false;
            }
        }
        return true;
    }
    public static Stack<Character> pushCharacter(String a){
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<a.length();i++){
            if(!(a.charAt(i)=='#')){
                stack.push(a.charAt(i));
            }else if(!(stack.empty())){
                stack.pop();
            }
        }
        return stack;
    }
    public static  boolean backspaceCompare(String s, String t) {
        Stack<Character> s_s=pushCharacter(s);
        Stack<Character> t_s=pushCharacter(t);
        while(!s_s.empty() && !t_s.empty()){
            if(s_s.pop() != t_s.pop()){
                return false;
            }
        }
        if(s_s.empty() && t_s.empty()){
            return true;
        }else{
            return false;
        }


    }

    public static void main(String[] args) {
       String s1="bxj##tw";
       String s2="bxj###tw";
       boolean ret=backspaceCompare(s1,s2);
        System.out.println(ret);
    }
}
